package service

import (
	"context"
	"errors"
	__ "service/basic/proto"
	"service/handler/model"
)

type Server struct {
	__.UnimplementedStreamGreeterServer
}

func (s *Server) Record(_ context.Context, in *__.RecordReq) (*__.RecordResp, error) {
	//验证用户
	var reservation model.Reservation
	reservation.UserId = uint(in.UserId)
	if err := reservation.GetRecordUserId(); err != nil {
		return nil, errors.New("用户信息查找失败")
	}
	if reservation.Id == 0 {
		return nil, errors.New("该用户未预约")
	}
	//验证医生
	var docker model.Docker
	docker.Id = uint(in.DockerId)
	if err := docker.GetDockerId(); err != nil {
		return nil, errors.New("医生信息查找失败")
	}
	if docker.Name == "" {
		return nil, errors.New("该医生身份有误")
	}
	//添加问诊信息
	record := model.Record{
		UserId:  uint(in.UserId),
		DocerId: uint(in.DockerId),
	}
	record.Create()
	return &__.RecordResp{
		Id: int64(record.Id),
	}, nil
}
